Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to use the structure 'for' ?

–1 vote
asked Dec 31, 2020 by Bechair Hechlef (130 points)

1 Answer

+3 votes
answered Jan 4, 2021 by Peter Minarik (84,720 points)

for is a keyword and the usage changes slightly from language to language. In C/C++ it has the following syntax:

for ([INITIALISATION]; [CONDITION]; [INCREMENT]) [INSTRUCTION]

where

  • INITIALISATION is typically setting up the start conditions of the for loop.
  • CONDITION is typically a logical expression to check whether the for loop should keep running (exit when it fails).
  • INCREMENT is typically an instruction to increment a loop variable for the next iteration of the loop
  • INSTRUCTION is the body of the loop to execute in every iteration
an actual example would be like this:
for (int i = 1; i <= 10; i++)
{
    printf("The %dth square number is: %d\n", i, i * i);
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...