Quantcast

Jump to content

» «
Photo

Using of For

3 replies to this topic
Inan-Ahammad
  • Inan-Ahammad

    Project Props - Mapper

  • Members
  • Joined: 15 Jul 2016
  • Bangladesh

#1

Posted 18 June 2017 - 07:08 PM

Hello guys i got a big problem with for tag.I read many books bu couldnt understand....Can anyone give an example of for in a prigram and tell me in details about its uasge..Thanks it would be much helpful.

trip
  • trip

    ~

  • Andolini Mafia Family
  • Joined: 10 Oct 2007
  • United-States
  • Contribution Award [GTAF]
    Contribution Award [Gen Chat]
    Contribution Award [GTAF Census]
    Doggo-Chop Winner 2016

#2

Posted 18 June 2017 - 07:29 PM

For is a loop the will run for a set number of times.

For (int x; x <=10; x++)
{
//code between these brackets will run 10 times.  And each time you can read the value of x if needed.
}
A while loop will need a condition to be met before it leaves it s code block.
Random myRandom;
While (myRandom!=10)
{
myRandom.next(200);
//code between the brackets will run foreber until the value of myRandom=10.  
}

IMO loops and conditions are the core of "programming". Once you understand loops and conditions you can pretty much code in any language.

Inan-Ahammad
  • Inan-Ahammad

    Project Props - Mapper

  • Members
  • Joined: 15 Jul 2016
  • Bangladesh

#3

Posted 31 July 2017 - 05:30 PM

For is a loop the will run for a set number of times.

For (int x; x <=10; x++)
{
//code between these brackets will run 10 times.  And each time you can read the value of x if needed.
}
A while loop will need a condition to be met before it leaves it s code block.
Random myRandom;
While (myRandom!=10)
{
myRandom.next(200);
//code between the brackets will run foreber until the value of myRandom=10.  
}
IMO loops and conditions are the core of "programming". Once you understand loops and conditions you can pretty much code in any language.
Thanks bro.I kindda got it now.

Gian_Yagami
  • Gian_Yagami

    Trick

  • Members
  • Joined: 08 Nov 2011
  • None

#4

Posted 10 January 2018 - 11:49 PM

Using function object that depends of algorithm inside them.

"for" is control flow used for fixed iteration.

"for" have 3 parameter statement, separated by semicolon (;) here' them:

for(parameter 1; parameter 2; parameter 3)

Parameter 1: it is initiation value, you can also declare variable here.

Parameter 2: it is condition statement, looping do until this condition false.

Parameter 3: it is increment, this statement execute after all task inside of { } executed.

Here' example "for" with inside declaration:

for(int x=0; x<10; x++){
task1;
task2;
.
.
.
Taskn;
}

Here example "for" without inside declaration:

Int x; //you can put this anywhere before the "for" executed

for(x=0; x<10; x++){
Task1;
Task2;
.
.
.
Taskn;
}

Increments x++ triggered after Taskn execute.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users