Web Hosting Unlimited Faster SSD IPv6 HTTP/2 + SSL Certificates
Ad High performance linux servers implementing ISPConfig open source control panel with newest connectivity, encryption and protocol support

Do ... while structure improvement

Sometimes the use of jumps such as: continue break goto call is necessary to avoid the execution of some instructions.

We suggest this improvement as a replacement for tricks like for(;;) if(condition)break; and jumps.

//allow initializers (extra improvement)
do(bool condition=0){
 //block A
}while(condition){
 //block B & initializer still visible
}

Example print arrays separating its elements

This code prints the content of an array, separating each of its elements by a comma, avoiding the printing of a comma after the last element.

#include<iostream>
using namespace std;

int main(){
 unsigned a[]={0,1,2,3,4,5,6,7,8,9};
 do(unsigned b=0){
  cout<<a[b];
 }while(++b<10){
  cout<<',';
 }
 cout<<endl;
 return 0;
}

Example auxiliary variables remain unchanged after last cycle

Sometimes a loop requires auxiliary variables, which change each cycle, but after the last one, they must either remain unchanged or it is useless to change them.

int main(){
 unsigned int loop1=0;
 unsigned int loop2;
 unsigned int result=0;
 unsigned int auxiliary1=1,auxiliary2=2,auxiliary3=3;
 while(loop1++<1000000000){
  //allow initializers (extra improvement)
  do(loop2=0){
   result+=auxiliary1;
   result-=auxiliary2;
   result*=auxiliary3;
  }while(++loop2<10){
   //auxiliaries remain unchanged
   auxiliary1+=auxiliary3;
   auxiliary2*=auxiliary1;
   auxiliary3-=auxiliary2;
  }
 }
 return 0;
}