M
M
Misha Yagudin2018-02-28 23:43:39
C++ / C#
Misha Yagudin, 2018-02-28 23:43:39

How to remove a statement after one iteration of a loop in C++?

For example, there is a loop:
for (; ;) {
if (condition) {
//do_something
}
// remaining body
}
If at the beginning I only need one check on the first iteration - can I remove it after it goes through?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2018-02-28
@summert

Delete is not possible. You can write a check "whether this is the first iteration".

P
polar_winter, 2018-03-27
@polar_winter

#include <iostream>

int main (int argc, char ** argv)
{
    int i =1;
    for ( (std::cout << "Hello word",i =0) ; i < 10 ; i++)

    {
        std::cout << i<<std::endl;
    }
    
    return 0;

Hello word, 00
1
2
3
4
5
6
7
8
9
You can use an initializing statement.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question