Sunday, December 31, 2017

Iterative statements in C++ and Python (Part 1)

while iterative statement

Set of statements can be executed repeatedly until a condition is met.

C++ Python
Syntax

while (condition)
{
        statement1;
        statement2;
                ...
}
Syntax

while condition:
        statement1;
        statement2;
                ... 







Example

int num = 1;

 while (num<=10)
{
      cout<<num<<"x2="<<num*2;
      num = num+1;
}
Example

num = 1

while num<=10:
     print("%d x2 = %d"%(num,num*2))
     num = num + 1
 


No comments:

Post a Comment

Iterative statements in C++ and Python (Part 2)

for loop iterative statements Executing set of statements using for iterative statement in C++ and Python is quite different. First, l...