function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lonely boylonely boy 

Print numbers 1 to 100 by skipping 40 to 60.How can I achieve this?

ANUTEJANUTEJ (Salesforce Developers) 
Hi there, 

You can try below code once:

for(integer i=1;i<=100;i++)
{
if(i>=40 && i<=60)
{continue;}
else
{ system.debug(i);}
}

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
RituSharmaRituSharma
You may use below code:

for(integer i=1;i<=100;i++) {
    if(i<40 || i>60){ 
        system.debug(i);
    }
}
Sachin HoodaSachin Hooda
Integer i = 0; 
while(i < 100){ 
   System.debug(i);
    i++; 
     if(i == 41) i+=20;
}
This would work too!