<commit_before>=================================
Control Structures - Second Style
=================================

In this chapter we are going to learn about the second style of control structures
provided by the Ring programming language.

.. index:: 
	pair: Control Structures; Branching


Branching
=========

* If Statement

Syntax:

.. code-block:: none

	if Expression
		Block of statements
	elseif Expression
		Block of statements
	else
		Block of statements
	end

Example:

.. code-block:: none

	put " 
		Main Menu
		---------
		(1) Say Hello
		(2) About
		(3) Exit

	    " get nOption

	if nOption = 1	put "Enter your name : " get name put "Hello " + name + nl
	elseif nOption = 2 put "Sample : using if statement" + nl
	elseif nOption = 3 bye
	else put "bad option..." + nl
	end


* Switch Statement

Syntax:

.. code-block:: none

	switch Expression
	case Expression
		Block of statements
	else
		Block of statements
	end		

Example:

.. code-block:: none

	Put " 
		Main Menu
		---------
		(1) Say Hello
		(2) About
		(3) Exit

	    " Get nOption

	Switch nOption
	Case 1 Put "Enter your name : " Get name Put "Hello " + name + nl
	Case 2 Put "Sample : using switch statement" + nl
	Case 3 Bye
	Else Put "bad option..." + nl
	End

.. index:: 
	pair: Control Structures; Looping

Looping
=======

* While Loop

Syntax:

.. code-block:: none

	while Expression
		Block of statements
	end


Example:

.. code-block:: none

	While True

		Put " 
			Main Menu
			---------
			(1) Say Hello
			(2) About
			(3) Exit

		    " Get nOption

		Switch nOption
		Case 1 
			Put "Enter your name : " 
			Get name 
			Put "Hello " + name + nl
		Case 2 
			Put "Sample : using while loop" + nl
		Case 3 
			Bye
		Else 
			Put "bad option..." + nl
		End
	End


* For Loop

Syntax:

.. code-block:: none

	for identifier=expression to expression [step expression]
		Block of statements
	end

* For in Loop

Syntax:

.. code-block:: none
<commit_msg>Update Documentation - controlstructures2.txt - Add examples.<commit_after>=================================
Control Structures - Second Style
=================================

In this chapter we are going to learn about the second style of control structures
provided by the Ring programming language.

.. index:: 
	pair: Control Structures; Branching


Branching
=========

* If Statement

Syntax:

.. code-block:: none

	if Expression
		Block of statements
	elseif Expression
		Block of statements
	else
		Block of statements
	end

Example:

.. code-block:: none

	put " 
		Main Menu
		---------
		(1) Say Hello
		(2) About
		(3) Exit

	    " get nOption

	if nOption = 1	put "Enter your name : " get name put "Hello " + name + nl
	elseif nOption = 2 put "Sample : using if statement" + nl
	elseif nOption = 3 bye
	else put "bad option..." + nl
	end


* Switch Statement

Syntax:

.. code-block:: none

	switch Expression
	case Expression
		Block of statements
	else
		Block of statements
	end		

Example:

.. code-block:: none

	Put " 
		Main Menu
		---------
		(1) Say Hello
		(2) About
		(3) Exit

	    " Get nOption

	Switch nOption
	Case 1 Put "Enter your name : " Get name Put "Hello " + name + nl
	Case 2 Put "Sample : using switch statement" + nl
	Case 3 Bye
	Else Put "bad option..." + nl
	End

.. index:: 
	pair: Control Structures; Looping

Looping
=======

* While Loop

Syntax:

.. code-block:: none

	while Expression
		Block of statements
	end


Example:

.. code-block:: none

	While True

		Put " 
			Main Menu
			---------
			(1) Say Hello
			(2) About
			(3) Exit

		    " Get nOption

		Switch nOption
		Case 1 
			Put "Enter your name : " 
			Get name 
			Put "Hello " + name + nl
		Case 2 
			Put "Sample : using while loop" + nl
		Case 3 
			Bye
		Else 
			Put "bad option..." + nl
		End
	End


* For Loop

Syntax:

.. code-block:: none

	for identifier=expression to expression [step expression]
		Block of statements
	end

Example:

.. code-block:: none

	# print numbers from 1 to 10
	for x = 1 to 10	 put x + nl  end

Example:

.. code-block:: none

	# Dynamic loop
	Put "Start : " get nStart       
	Put "End   : " get nEnd
	Put "Step  : " get nStep
	For x = nStart to nEnd Step nStep
		Put x + nl
	End

Example:

.. code-block:: none

	# print even numbers from 0 to 10
	for x = 0 to 10 step 2
		Put x + nl
	end

Example:

.. code-block:: none

	# print even numbers from 10 to 0
	for x = 10 to 0 step -2
		put x + nl
	end


* For in Loop

Syntax:

.. code-block:: none

{'fraction_non_alphanumeric': 0.1280323450134771, 'fraction_numerical': 0.012803234501347708, 'mean_word_length': 2.4653696498054476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2212245', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1448, 'n_words': 590}