Difference between revisions of "C-and-C++/C4/Working-With-Structures/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 1: Line 1:
+
{| border = 1
{| border=1
+
 
|| ''Time'''
+
|'''Time'''
|| '''Narration'''
+
 
 +
|'''Narration'''
  
  
 
|-
 
|-
| 00:01
+
| 00.01
| Welcome to the spoken-tutorial on '''Structures '''in '''C''' and '''C++.'''
+
|Welcome to the spoken tutorial on Loops in C and C++  
  
 
|-
 
|-
| 00:06
+
| 00.06
| In this tutorial we will learn
+
|In this tutorial we will learn
  
 +
|-
 +
| 00.09
 +
|for loop,
  
 
|-
 
|-
| 00:09
+
| 00.10
|   what is a '''Structure'''.
+
|while loop and
  
 +
|-
 +
| 00.12
 +
|do…while loop.
  
 
|-
 
|-
| 00:11
+
| 00.13
| Declaration of a '''structure'''
+
| We will do this with the help of some examples.
  
 +
|-
 +
| 00.17
 +
|We will also see some common errors and their solutions.
  
 
|-
 
|-
| 00:13
+
| 00.21
| We will do this through an example
+
| To record this tutorial, I am using
  
 +
|-
 +
| 00.24
 +
|Ubuntu Operating System version 11.04
  
 +
|-
 +
|00.28
 +
| gcc and g++ Compiler version 4.6.1 on Ubuntu.
  
  
 
|-
 
|-
| 00:16
+
|00.34
| To record this tutorial, I am using,
+
|Let us start with the introduction to loops.
  
 +
|-
 +
|00.38
 +
|Loops are used to execute a group of instructions repeatedly.
  
 
|-
 
|-
| 00:19
+
| 00.44
| '''Ubuntu Operating System''' version 11.10,
+
|Depending on the purpose they are divided into three types:  
 +
 
 +
|-
 +
| 00.48
 +
|while loop
  
  
 
|-
 
|-
| 00:23
+
| 00.49
| '''gcc''' and '''g++''' '''Compiler''' version 4.6.1
+
|do…..while loop and
  
 
|-
 
|-
| 00:29
+
| 00.51
| Let us start with an introduction to '''Structure'''
+
|for loop
  
 +
|-
 +
| 00.52
 +
|Let us start with the while loop first
  
 
|-
 
|-
| 00:32
+
| 00.56
| When one or more variables are grouped under one name it is known as '''structure'''.
+
|A while loop tests the condition in the beginning
  
 +
|-
 +
| 00.59
 +
|The structure is
  
 
|-
 
|-
| 00:38
+
| 01.01
| Strucutre is used to group different data into one object.
+
|while ( condition )
  
 +
|-
 +
|01.03
 +
|within the bracket statement block
  
 
|-
 
|-
| 00:43
+
| 01.07
| It is called as '''compound data-type'''.
+
|Now move on to  do….while loop
  
 +
|-
 +
| 01.09
 +
|A do..while loop is executed at least once before the condition could be validated.
  
 
|-
 
|-
| 00:45
+
| 01.15
| It is used to group related information together.
+
|The structure is
  
 
|-
 
|-
| 00:49
+
| 01.17
| Now we will see
+
|do (within the brackets) statement block
  
  
 
|-
 
|-
| 00:50
+
|01.20
| The syntax to declare a '''structure'''
+
|after the bracket the while ( condition )
  
 +
|-
 +
|01.23
 +
|You can see that the condition is checked at the end.
  
 
|-
 
|-
| 00:53
+
| 01.27
| Here the keyword''' struct '''tells the compiler that a structure is declared
+
|Now,let us see an example on while loop and do...while loop
  
 +
|-
 +
| 01.32
 +
|I have already typed the code on the editor.
  
 
|-
 
|-
| 00:59
+
| 01.35
| '''strcut_name''' is the name of the '''structure'''.
+
|Let me open it.  
  
 +
|-
 +
|01.37
 +
|Note that our file name is while.c.
  
 
|-
 
|-
| 01:03
+
|01.41
| eg. '''struct employee;'''
+
|Today we are going to learn addition of first 10 numbers using while loop.
  
 +
|-
 +
|01.47
 +
|Let me explain the code now.
  
 
|-
 
|-
| 01:05
+
|01.49
| You can give any name.
+
|This is our header file.
  
 
|-
 
|-
| 01:07
+
| 01.51
| Now we will see how to declare a '''structure''' '''variable'''.
+
|Inside the main function we have declared two integer variables x and y and initialized to 0.
 +
 
  
  
 
|-
 
|-
| 01:12
+
| 01.59
| Syntax for this is
+
| This is our while loop.
 +
 
 +
|
 +
|-
 +
| 02.02
 +
| The condition of the while loop is x is less than or equal to 10.
  
  
 
|-
 
|-
| 01:14
+
|02.06
| '''struct struct_name  and struct_var;'''
+
|Here the value of x is added to the value of y.
  
  
 
|-
 
|-
| 01:17
+
| 02.10
| '''struct_var''' is the variable of type '''struc_name'''
+
| The value obtained after the addition is stored in y.
  
 +
|-
 +
| 02.15
 +
| Then we print the value of y
  
 
|-
 
|-
| 01:22
+
| 02.18
| eg. '''struct employee addr;'''
+
| Here  x is incremented.  
  
 +
|-
 +
| 02.20
 +
| That means the variable x is increased by one.
  
 
|-
 
|-
| 01:27
+
| 02.25
| '''addr''' is the '''variable''' of type '''employee.'''
+
|And this is our return statement.
  
 
|-
 
|-
| 01:31
+
| 02.27
| Let us move on to our example
+
|Now,let us execute the program.
  
 
|-
 
|-
| 01:33
+
| 02.30
|   I have already typed the program on the editor
+
| Please open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard.
  
 +
|-
 +
| 02.39
 +
|Type gcc space while dot c space hypen o space while
  
 
|-
 
|-
| 01:36
+
| 02.45
| So let me open it.
+
|Press Enter
 +
 
  
 
|-
 
|-
| 01:38
+
| 02.47
| Note that our filename is '''structure.c'''
+
|Type ./ (dot slash) while .Press Enter
 +
 
  
 
|-
 
|-
| 01:42
+
| 02.52
| In this program we will calculate the total marks of three subjects using structure
+
| The output is displayed.
  
 
|-
 
|-
| 01:49
+
| 02.54
|   Let me explain the code now.
+
| Now lets us see the working of while loop.
  
 
|-
 
|-
| 01:51
+
| 02.57
+
|Let me resize the window.
|   This is our header file.
+
  
 
|-
 
|-
| 01:53
+
| 03.00
| Here we have declared a '''structure '''as''' student'''.
+
|Here, first the  value of x and y is 0
  
  
 +
|-
 +
| 03.04
 +
|This is our while condition.Here we check whether x is less than or equal to 10 which means the values of x will be from 0 to 10
  
 +
|-
 +
| 03.15
 +
|Then we  add y plus x (i.e)  0 plus 0 we get 0. We print the value of y, here we get 0. Then x is incremented which means now the value of x will be 1
  
 
|-
 
|-
| 01:57
+
| 03.33
|   Then we have declared three integer variables as '''english, maths '''and '''science'''.
+
|Then we will check the condition again, 1 is less than or equal to 10, if the condition is true then we will add the values, y (i.e ) 0 plus x that is 1. 0 plus 1 is 1
  
 +
|-
 +
| 03.50
 +
|We print the value as 1.Again x is incremented.
  
 
|-
 
|-
| 02:04
+
| 03.55
| Variables defined under the structure are called as members of the structure.
+
|Now the value of x is 2.We check the condition again. 2 is less than or equal to 10, if the condition is true then we will add the values,(i.e ) 1 plus 2 which will give 3.
  
 
|-
 
|-
| 02:10
+
| 04.11
| This is our main function
+
|We print the value as 3. Like this it will go on upto x is less than or equal to 10
 +
|-
 +
| 04.20
 +
| Now, we will see the same program using do….while loop
  
 
|-
 
|-
| 02:12
+
| 04.24
| Here we have declared an integer variable''' total'''.
+
| Here is our program
  
 
|-
 
|-
| 02:17
+
| 04.26
| Now we have declared a structure variable '''stud'''. ''' stud '''is the variable of type student,it is used to access and modify the structure members
+
|Note that our file name is do hypen while.c
  
 +
|-
 +
| 04.31
 +
|This part is already explained in the previous program.So lets us move on to a do...while loop
  
 +
|-
 +
| 04.38
 +
|Here first the body of the loop will be executed  and then the condition is checked.The value of x is added to the value of y and the value obtained after the addition is totalled y
  
 +
|-
 +
| 04.52
 +
|The logic is same as in while program
  
 
|-
 
|-
| 02:30
+
| 04.55
| Here we have modified the members
+
|Now lets us execute the program
  
 
|-
 
|-
| 02:32
+
| 04.58
|By assigning them values  as 75, 70 and 65.
+
|Come back to our terminal
  
 
|-
 
|-
| 02:38
+
| 05.00
|   Here we calculate the total of  three subjects.
+
|Type gcc space do hypen while dot c space hypen o space do.Press Enter
  
 
|-
 
|-
| 02:42
+
| 05.08
|   Then we print the result.
+
|Type dot slash do. Press Enter
  
 
|-
 
|-
|   02:44
+
| 05.12
| This is our return statement.
+
|We can see that the output is similiar  to our while program
  
 
|-
 
|-
| 02:47
+
| 05.16
| Now click on '''Save'''
+
|Now, lets us see the working of do...while loop
  
 
|-
 
|-
| 02:49
+
| 05.20
|   Let us execute the program
+
|Let me resize the window
  
 
|-
 
|-
| 02:51
+
| 05.22
| Please open the terminal window by pressing
+
|Here the value x and y is 0
  
 
|-
 
|-
| 02:54
+
| 05.25
|'''Ctrl, Alt''' and '''T''' keys simultaneously on your keyboard.
+
|We add those values then we will get 0
  
 
|-
 
|-
| 03:00
+
| 05.29
|   To compile
+
|Now the value of y is 0. We print the value as 0
  
 
|-
 
|-
| 03:01
+
| 05.33
|Type; '''gcc '''space '''structure.c '''space '''-o '''space''' struct'''
+
|Then x is incremented by 1 which means now the value of x is 1, then the condition will be checked.
  
 
|-
 
|-
| 03:10
+
| 05.40
|And press''' Enter'''
+
| You can see that the body of loop is executed first. Anyhow if the condition is false then also we will get the values that is 0.
  
 
|-
 
|-
| 03:12
+
| 05.52
|To execute
+
|Now, here we will check whether 1 is less than or equal to 10
 +
 
  
 
|-
 
|-
| 03:13
+
| 05.56
|Type'''./struct''' Press''' Enter '''
+
|The condition is true again we will add the values. Now 0 plus 1. Then we will print the value of y as 1
  
 
|-
 
|-
| 03:18
+
| 06.05
|   The output is displayed as: Total is 210
+
|Again x will be incremented.Now the value of x is 2. Then we check 2 is less than or equal to 10
  
 
|-
 
|-
| 03:22
+
| 06.15
| Now we will execute the same program in C++
+
|We will go back here
  
 
|-
 
|-
| 03:26
+
| 06.17
| Come back to our program.
+
|Then we will add the values 1 plus 2 is 3
  
 
|-
 
|-
| 03:28
+
| 06.20
|   I will edit the same code
+
| We print the value of y as 3
  
 
|-
 
|-
|   03:31
+
| 06.23
| First press '''shift''', '''cntrl '''and '''S''' keys simultaneously on the keyboard
+
|Like this the conditions will be checked till the value of x will be less than or equal to 10
  
 
|-
 
|-
| 03:37
+
| 06.30
|Now save the file with an extension '''.cpp'''  and click on save
+
|And this is our return statement.
  
 
|-
 
|-
| 03:44
+
| 06.33
| Let us change the header file as '''iostream'''
+
|Note that here the while condition ends with the semicolon
  
 
|-
 
|-
| 03:48
+
| 06.38
| Now include the '''using''' statement and click on''' save'''
+
|In while loop the condition does not end with the semicolon.
  
 
|-
 
|-
| 03:57
+
| 06.43
| Structure declaration in '''C++ '''is same as in''' C'''
+
|Now lets us see how to execute these programs in C++
  
 
|-
 
|-
| 04:02
+
| 06.48
|So no need to change anything here
+
|This is our while program in C++
  
 
|-
 
|-
| 04:05
+
| 06.52
|   At the end we will replace the printf statement with the ''' cout  ''' statement.
+
|The logic and implementation are same as in our C program
  
 
|-
 
|-
| 04:08
+
| 06.56
|   Delete the format specifier and '''\n'''
+
|There are a few changes like the header file as iostream in place of stdio.h
 +
 
  
 
|-
 
|-
| 04:16
+
| 07.04
|Now delete the comma
+
|We have included the using statement here using namespace std and here we have use the cout function in place of printf function
  
 
|-
 
|-
| 04:17
+
| 07.16
|Type two opening angle brackets.  
+
|The structure of while loop is same as in our C program.
  
 
|-
 
|-
| 04:21
+
| 07.21
|Here delete the closing bracket
+
|Lets us execute the program
  
 
|-
 
|-
| 04:23
+
| 07.23
|and type two opening angle backets
+
|Come back to a terminal
  
 
|-
 
|-
| 04:25
+
| 07.25
|And within the double quotes type '''\n'''
+
|Let me clear the prompt
 +
 
  
 
|-
 
|-
| 04:29
+
| 07.28
| Now click on '''Save'''
+
|To execute type g++ space do , g++ space while dot cpp space hypen o space while1. Press Enter
  
 
|-
 
|-
|   04:31
+
| 07.41
| Let us execute the program
+
|Type dot slash while1.Press Enter
  
 
|-
 
|-
|   04:33
+
| 07.46
|   Come back to our terminal
+
|You can see that the output is similiar to our while program in C.
  
 
|-
 
|-
| 04:35
+
| 07.51
|To compile type '''g++ '''space''' structure.cpp '''space '''-o '''space''' struct1'''
+
|Now let us see the do... while program in C++
  
 
|-
 
|-
| 04:47
+
| 07.55
|Here we have struct1 because we dont want to overwrite the output parameters for the file''' structure.c'''
+
|Come back to the Text editor
  
 
|-
 
|-
| 04:55
+
| 07.57
|Now press '''Enter'''
+
|Here also there are similiar changes like the header file,the using statement and the cout function
  
 
|-
 
|-
| 04:57
+
| 08.06
|To execute type '''./struct1'''
+
|Rest of the things are similiar
  
 
|-
 
|-
| 05:02
+
| 08.09
|Press''' Enter '''
+
|Lets us execute the program.Come back to our terminal
  
 
|-
 
|-
| 05:04
+
| 08.13
| The output is displayed as: '''Total is 210'''
+
|Type g++ space do hypen while dot cpp space hypen o space do1. Press Enter
  
 
|-
 
|-
| 05:08  
+
| 08.23
|You can see that the output is same as our '''C '''code
+
|Type dot slash do1.Press Enter
  
 
|-
 
|-
| 05:12
+
| 08.26
|Now  let us go  back to our slides.
+
|We can see that the output is similiar to our do...while program in C.
  
 
|-
 
|-
| 05:15
+
| 08.32
| We will summarize now. In this tutorial we learned,
+
|Now we will see some common errors and their solutions
  
 
|-
 
|-
| 05:18
+
| 08.35
|Structure.
+
|Come back to our text editor
  
 
|-
 
|-
| 05:19
+
| 08.38
|Syntax of a structure.
+
|Suppose here I will not increment the value of x.Click on Save. Let us see what happens
  
 
|-
 
|-
| 05:21
+
| 08.46
|eg. '''struct struct_name;'''
+
|Come back to the terminal. Let me clear the prompt
  
 
|-
 
|-
| 05:24
+
| 08.50
|To access members of a structure.
+
|Lets us execute the program. Press the uparrow key twice. Again press the uparrow key
  
 
|-
 
|-
| 05:26
+
| 09.00
|'''Eg: stud.maths = 75; '''
+
|The output is displayed. We can see number of zeros, this is because the loop does not have the terminating condition . It is known as infinite loop
 +
 
  
 
|-
 
|-
| 05:30
+
| 09.13
|To add the structure variables.
+
|Infinite loop can cause the system to become unresponsive. It causes the program to consume all the prossess time but it can be terminated
  
 
|-
 
|-
| 05:33
+
| 09.25
|'''Eg: total = stud.eng + stud.maths + stud.science; '''
+
|Come back to our program let us fix the error. Type x++ and a semicolon.
  
 
|-
 
|-
| 05:40
+
| 09.31
| | As an assignment,
+
|Click on Save. Lte us execute again. Come back to terminal.
  
 
|-
 
|-
| 05:41
+
| 09.36
|Write a program to diplay the records of an employee.
+
|Press the uparrow key
  
 
|-
 
|-
| 05:45
+
| 09.41
|Like name, address, designation, salary.
+
|Yes, it is working
  
 
|-
 
|-
| 05:49
+
| 09.43
| Watch the video available at the link shown below
+
|This bring us to the end of the tutorial. We will move back to our slides.
  
 
|-
 
|-
| 05:53
+
| 09.49
|It summarises the Spoken Tutorial project
+
|Let us summarize
 +
 
  
 
|-
 
|-
| 05:55
+
| 09.50
|If you do not have good bandwidth, you can download and watch it
+
|In this tutorial we learned,  
  
 
|-
 
|-
| 06:00
+
| 09.52
| | The Spoken Tutorial Project Team
+
|while loop
  
 
|-
 
|-
| 06:02
+
| 09.53
 +
|example. while(x is less than or equal to10)
 +
 
 +
|-
 +
| 09.57
 +
|do….while loop
 +
 
 +
|-
 +
| 09.58
 +
|example. do statement block and
 +
 
 +
 
 +
|-
 +
| 10.02
 +
|while condition at the end
 +
 
 +
|-
 +
| 10.04
 +
|As an assignment
 +
 
 +
|-
 +
| 10.06
 +
|Write a program to print the following using for loops
 +
 
 +
|-
 +
| 10.10
 +
|0 to 9
 +
 
 +
|-
 +
| 10.12
 +
|The syntax of the for loop is
 +
 
 +
|-
 +
| 10.15
 +
|for (variable initialization; variable condition;and variable increment or decrement)
 +
 
 +
|-
 +
| 10.24
 +
|And here will be the body of the loop
 +
 
 +
 
 +
 
 +
 
 +
 
 +
|-
 +
| 10.27
 +
|Watch the video available at the link shown below
 +
 
 +
|-
 +
| 10.30
 +
|It summarizes the Spoken Tutorial project
 +
 
 +
|-
 +
| 10.32
 +
|If you do not have good bandwidth, you can download and watch it
 +
 
 +
|-
 +
| 10.36
 +
|The Spoken Tutorial Project Team
 +
 
 +
|-
 +
| 10.38
 
|Conducts workshops using spoken tutorials  
 
|Conducts workshops using spoken tutorials  
  
 
|-
 
|-
| 06:05
+
| 10.41
 
|Gives certificates to those who pass an online test  
 
|Gives certificates to those who pass an online test  
  
 
|-
 
|-
| 06:08
+
| 10.45
|For more details, please write to contact@spoken-tutorial.org
+
|For more details, please write to, contact@spoken-tutorial.org  
  
 
|-
 
|-
| 06:15
+
| 10.50
| Spoken Tutorial Project is a part of the Talk to a Teacher project
+
|Spoken Tutorial Project is a part of Talk to a Teacher project  
  
 
|-
 
|-
| 06:19
+
| 10.55
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India
 
|It is supported by the National Mission on Education through ICT, MHRD, Government of India
  
 
|-
 
|-
| 06:26
+
| 11.01
|More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro
+
|More information on this Mission is available at the link shown below
  
 
|-
 
|-
| 06:30
+
| 11.05
| This is Ashwini Patil from IIT Bombay. Siginning off.
+
|This script as been contributed by Dhawal Goyal. This is Ashwini Patil from IIT Bombay signing off  
  
 
|-
 
|-
| 06:33
+
| 11.12
|Thank You for joining
+
|Thank You for joining.
 
+
|}
+

Revision as of 10:32, 22 November 2013

Time Narration


00.01 Welcome to the spoken tutorial on Loops in C and C++
00.06 In this tutorial we will learn,
00.09 for loop,
00.10 while loop and
00.12 do…while loop.
00.13 We will do this with the help of some examples.
00.17 We will also see some common errors and their solutions.
00.21 To record this tutorial, I am using
00.24 Ubuntu Operating System version 11.04
00.28 gcc and g++ Compiler version 4.6.1 on Ubuntu.


00.34 Let us start with the introduction to loops.
00.38 Loops are used to execute a group of instructions repeatedly.
00.44 Depending on the purpose they are divided into three types:
00.48 while loop


00.49 do…..while loop and
00.51 for loop
00.52 Let us start with the while loop first
00.56 A while loop tests the condition in the beginning
00.59 The structure is
01.01 while ( condition )
01.03 within the bracket statement block
01.07 Now move on to do….while loop
01.09 A do..while loop is executed at least once before the condition could be validated.
01.15 The structure is
01.17 do (within the brackets) statement block


01.20 after the bracket the while ( condition )
01.23 You can see that the condition is checked at the end.
01.27 Now,let us see an example on while loop and do...while loop
01.32 I have already typed the code on the editor.
01.35 Let me open it.
01.37 Note that our file name is while.c.
01.41 Today we are going to learn addition of first 10 numbers using while loop.
01.47 Let me explain the code now.
01.49 This is our header file.
01.51 Inside the main function we have declared two integer variables x and y and initialized to 0.


01.59 This is our while loop.
02.02 The condition of the while loop is x is less than or equal to 10.


02.06 Here the value of x is added to the value of y.


02.10 The value obtained after the addition is stored in y.
02.15 Then we print the value of y
02.18 Here x is incremented.
02.20 That means the variable x is increased by one.
02.25 And this is our return statement.
02.27 Now,let us execute the program.
02.30 Please open the terminal window by pressing Ctrl, Alt and T keys simultaneously on your keyboard.
02.39 Type gcc space while dot c space hypen o space while
02.45 Press Enter


02.47 Type ./ (dot slash) while .Press Enter


02.52 The output is displayed.
02.54 Now lets us see the working of while loop.
02.57 Let me resize the window.
03.00 Here, first the value of x and y is 0


03.04 This is our while condition.Here we check whether x is less than or equal to 10 which means the values of x will be from 0 to 10
03.15 Then we add y plus x (i.e) 0 plus 0 we get 0. We print the value of y, here we get 0. Then x is incremented which means now the value of x will be 1
03.33 Then we will check the condition again, 1 is less than or equal to 10, if the condition is true then we will add the values, y (i.e ) 0 plus x that is 1. 0 plus 1 is 1
03.50 We print the value as 1.Again x is incremented.
03.55 Now the value of x is 2.We check the condition again. 2 is less than or equal to 10, if the condition is true then we will add the values,(i.e ) 1 plus 2 which will give 3.
04.11 We print the value as 3. Like this it will go on upto x is less than or equal to 10
04.20 Now, we will see the same program using do….while loop
04.24 Here is our program
04.26 Note that our file name is do hypen while.c
04.31 This part is already explained in the previous program.So lets us move on to a do...while loop
04.38 Here first the body of the loop will be executed and then the condition is checked.The value of x is added to the value of y and the value obtained after the addition is totalled y
04.52 The logic is same as in while program
04.55 Now lets us execute the program
04.58 Come back to our terminal
05.00 Type gcc space do hypen while dot c space hypen o space do.Press Enter
05.08 Type dot slash do. Press Enter
05.12 We can see that the output is similiar to our while program
05.16 Now, lets us see the working of do...while loop
05.20 Let me resize the window
05.22 Here the value x and y is 0
05.25 We add those values then we will get 0
05.29 Now the value of y is 0. We print the value as 0
05.33 Then x is incremented by 1 which means now the value of x is 1, then the condition will be checked.
05.40 You can see that the body of loop is executed first. Anyhow if the condition is false then also we will get the values that is 0.
05.52 Now, here we will check whether 1 is less than or equal to 10


05.56 The condition is true again we will add the values. Now 0 plus 1. Then we will print the value of y as 1
06.05 Again x will be incremented.Now the value of x is 2. Then we check 2 is less than or equal to 10
06.15 We will go back here
06.17 Then we will add the values 1 plus 2 is 3
06.20 We print the value of y as 3
06.23 Like this the conditions will be checked till the value of x will be less than or equal to 10
06.30 And this is our return statement.
06.33 Note that here the while condition ends with the semicolon
06.38 In while loop the condition does not end with the semicolon.
06.43 Now lets us see how to execute these programs in C++
06.48 This is our while program in C++
06.52 The logic and implementation are same as in our C program
06.56 There are a few changes like the header file as iostream in place of stdio.h


07.04 We have included the using statement here using namespace std and here we have use the cout function in place of printf function
07.16 The structure of while loop is same as in our C program.
07.21 Lets us execute the program
07.23 Come back to a terminal
07.25 Let me clear the prompt


07.28 To execute type g++ space do , g++ space while dot cpp space hypen o space while1. Press Enter
07.41 Type dot slash while1.Press Enter
07.46 You can see that the output is similiar to our while program in C.
07.51 Now let us see the do... while program in C++
07.55 Come back to the Text editor
07.57 Here also there are similiar changes like the header file,the using statement and the cout function
08.06 Rest of the things are similiar
08.09 Lets us execute the program.Come back to our terminal
08.13 Type g++ space do hypen while dot cpp space hypen o space do1. Press Enter
08.23 Type dot slash do1.Press Enter
08.26 We can see that the output is similiar to our do...while program in C.
08.32 Now we will see some common errors and their solutions
08.35 Come back to our text editor
08.38 Suppose here I will not increment the value of x.Click on Save. Let us see what happens
08.46 Come back to the terminal. Let me clear the prompt
08.50 Lets us execute the program. Press the uparrow key twice. Again press the uparrow key
09.00 The output is displayed. We can see number of zeros, this is because the loop does not have the terminating condition . It is known as infinite loop


09.13 Infinite loop can cause the system to become unresponsive. It causes the program to consume all the prossess time but it can be terminated
09.25 Come back to our program let us fix the error. Type x++ and a semicolon.
09.31 Click on Save. Lte us execute again. Come back to terminal.
09.36 Press the uparrow key
09.41 Yes, it is working
09.43 This bring us to the end of the tutorial. We will move back to our slides.
09.49 Let us summarize


09.50 In this tutorial we learned,
09.52 while loop
09.53 example. while(x is less than or equal to10)
09.57 do….while loop
09.58 example. do statement block and


10.02 while condition at the end
10.04 As an assignment
10.06 Write a program to print the following using for loops
10.10 0 to 9
10.12 The syntax of the for loop is
10.15 for (variable initialization; variable condition;and variable increment or decrement)
10.24 And here will be the body of the loop



10.27 Watch the video available at the link shown below
10.30 It summarizes the Spoken Tutorial project
10.32 If you do not have good bandwidth, you can download and watch it
10.36 The Spoken Tutorial Project Team
10.38 Conducts workshops using spoken tutorials
10.41 Gives certificates to those who pass an online test
10.45 For more details, please write to, contact@spoken-tutorial.org
10.50 Spoken Tutorial Project is a part of Talk to a Teacher project
10.55 It is supported by the National Mission on Education through ICT, MHRD, Government of India
11.01 More information on this Mission is available at the link shown below
11.05 This script as been contributed by Dhawal Goyal. This is Ashwini Patil from IIT Bombay signing off
11.12 Thank You for joining.

Contributors and Content Editors

Kavita salve, Krupali, PoojaMoolya, Pratik kamble, Sandhya.np14, Sneha