Give example of the for loop, C/C++ Programming

Assignment Help:

The for Loop

For loop is the controlled form of loop. The general format of this :

for( initialize ; test ; update)

                 {

                    statements;

                                :

                                :

                 }

The initialize part is implemented only once, before entering the loop. If test evaluates to false then the next statement after for loop is implemented. If the test evaluates to true then the updating takes place.

 

e.g.

for( int i = 0; i< 10; i++) // In C++ you can declare a

variable here.

                 {

                                cout << i;

                 }

This will print from 0 to 10.

The expressions in the for loop are optional but the semi-colons are essential, i.e.,

 

                for( ; ; )

                 {

                                cout<<"hello";

                 }

 

This  is an infinite loop, with no expression.

 

e.g.

                int i = 0

 

 

for(; i< 10; )

                 {

                                cout << i;

                                i++;

                 }

 

This is equivalent to our example, which printed from 0 to 9. More than one expression can also be inside the for loop by separating them using commas.

 

e.g.

                for( int i = 0, int j=10; i< 10 && y>0 ; i++, y--)

                 {

                                cout << i;

                 }

 


Related Discussions:- Give example of the for loop

Define the data type qualifiers in c language, Define the Data Type Qualifi...

Define the Data Type Qualifiers in c Language? 1. const 2. volatile const: The const qualifier is used to tell C that the variable value can't change after initialization.

Program is to define a class as library, Program is to define a class as li...

Program is to define a class as library: Program is to define a class as library and perform all the function of library management by using classes and object class librar

Illustrate the problems with multiple inheritance, Problems With Multiple I...

Problems With Multiple Inheritance The following example presents a problem with multiple inheritance. class Aclass  {   public :  void put()

Implementing functions, An employee’s total weekly pay equals the hourly wa...

An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular hours plus any overtime pay. Overtime pay equals the total overtime hours multiplied

Write a program that illustrate union declaration, Write a Program that ill...

Write a Program that illustrate union declaration? A C program encloses the following union declaration: union id { char color[12]; int size; } shirt, blouse; At this

Car rental project, I need a project on car rental system using c programmi...

I need a project on car rental system using c programming only of college level

Give example of the for loop, The for Loop For loop is the controlled f...

The for Loop For loop is the controlled form of loop. The general format of this : for( initialize ; test ; update)                  {                     statements;

Guidelines or "rules of thumb" for overloading operators?, What are some gu...

What are some guidelines / "rules of thumb" for overloading operators? A: Here are a few guidelines / rules of thumb .Use common sense. If your overloaded operator makes life si

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd