In this example you will see: For loop, while loop, do while loop, break, continue, array.reverse.

NOTIFICATION: These examples are provided for educational purposes. Using this code is under your own responsibility and risk. The code is given ‘as is’. I do not take responsibilities of how they are used.

Actual Example (SWF):

Sorry, either Adobe flash is not installed or you do not have it enabled

Code example: example2.hx:

class Example_2 {

	static function main(){

		//In haxe, arrays are iterable which mean that have methods and properties
		var integer_array : Array<Int> = [1,2,3,4];

		var num : Int = 4;
		for (i in 0...num)
			trace('1) integer_array[' + i + ']: ' + integer_array[i]);

		integer_array.reverse();

		for (i in 0...num)
			trace('2) integer_array[' + i + ']: ' + integer_array[i]);

		// While loop
		var count : Int = 0;
    while(count < 5){
			trace('3) While Count: ' + count);
    	++count;
    }

		count = 0;
		do{
			trace('4) Do While Count: ' + count);
    	count++;
    }while(count < 5);

		// continue - skip interation and go backi to while condition
		count = -1;
		while( count < 5 ) {
			++count;
			trace('5) While with continue Count: ' + count);
		  if( count == 3 ){
				trace('5) CONTINUE go to while');
	      continue;
		  }
		}
		trace('5) While with continue ends at count: ' + count);			

		// break - Jump out of the 'while' loop, and continue
		count = -1;
		while( count < 5 ) {
			++count;
			trace('6) While with break Count: ' + count);
		  if( count == 3 ){
				trace('6) Break!!!');
	      break;
		  }
		}
		trace('6) While with break ends at count: ' + count);			

  }

}

If you encounter any problems or errors, please let me know by providing an example of the code, input, output, and an explanation. Thanks.

© 2010 – 2011, Alejandro G. Carlstein Ramos Mejia. All rights reserved.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

*

Click to Insert Smiley

SmileBig SmileGrinLaughFrownBig FrownCryNeutralWinkKissRazzChicCoolAngryReally AngryConfusedQuestionThinkingPainShockYesNoLOLSillyBeautyLashesCuteShyBlushKissedIn LoveDroolGiggleSnickerHeh!SmirkWiltWeepIDKStruggleSide FrownDazedHypnotizedSweatEek!Roll EyesSarcasmDisdainSmugMoney MouthFoot in MouthShut MouthQuietShameBeat UpMeanEvil GrinGrit TeethShoutPissed OffReally PissedMad RazzDrunken RazzSickYawnSleepyDanceClapJumpHandshakeHigh FiveHug LeftHug RightKiss BlowKissingByeGo AwayCall MeOn the PhoneSecretMeetingWavingStopTime OutTalk to the HandLoserLyingDOH!Fingers CrossedWaitingSuspenseTremblePrayWorshipStarvingEatVictoryCurseAlienAngelClownCowboyCyclopsDevilDoctorFemale FighterMale FighterMohawkMusicNerdPartyPirateSkywalkerSnowmanSoldierVampireZombie KillerGhostSkeletonBunnyCatCat 2ChickChickenChicken 2CowCow 2DogDog 2DuckGoatHippoKoalaLionMonkeyMonkey 2MousePandaPigPig 2SheepSheep 2ReindeerSnailTigerTurtleBeerDrinkLiquorCoffeeCakePizzaWatermelonBowlPlateCanFemaleMaleHeartBroken HeartRoseDead RosePeaceYin YangUS FlagMoonStarSunCloudyRainThunderUmbrellaRainbowMusic NoteAirplaneCarIslandAnnouncebrbMailCellPhoneCameraFilmTVClockLampSearchCoinsComputerConsolePresentSoccerCloverPumpkinBombHammerKnifeHandcuffsPillPoopCigarette