கட்டுப்பாட்டு கட்டமைப்பு
கட்டற்ற கலைக்களஞ்சியமான விக்கிபீடியாவில் இருந்து.
ஒரு நிரலின் கட்டளைகளை நெறிப்படுத்த கட்டுப்பாட்டு கட்டமைப்பு (Control Structure) தேவை. கட்டுப்பாட்டு கட்டமைப்பில் தெரிவுகளும் (Choices), மடக்குசெயல்பாடும் (Repetions) அடிப்படையானவை.
பொருளடக்கம் |
[தொகு] தெரிவுகள்
தெரிவுகள் இரு வகைப்படும்:
[தொகு] இரு வழி தெரிவுகள்
if condition then statements; else condition then other statements; end if;
[தொகு] பல வழி தெரிவுகள்
case someChar of switch (someChar) {
'a': actionOnA; case 'a': actionOnA;
'x': actionOnX; break;
'y','z':actionOnYandZ; case 'x': actionOnX;
end; break;
case 'y':
case 'z': actionOnYandZ;
break;
default: actionOnNoMatch;
}
[தொகு] மடக்கி
ஒன்றை ஒரு செயல்பாட்டுக்குள் மடக்கி விடிவதை மடக்கி குறிப்பிடுகின்றது எனலாம். திரும்ப திரும்ப ஒரு குறிப்பிட்ட செயல்ப்பாட்டை செய்வதை மடக்கி என்று நிரலாக பின்புலத்தில் எடுத்துகொள்ளப்படுகின்றது. வளையம், கண்ணி, சுழல் செய்கை போன்ற சொற்களையும் இதற்கு தமிழில் பயன்படுத்தப்படுவதுண்டு.
மடக்கி கட்டமைப்பில் இரு விடயங்கள் கவனிக்க தக்கன, அவை:
- மடக்கி எப்படி கட்டுப்படுத்தப்படுகின்றது?
- மடக்கிக்கான கட்டுப்பாடு எங்கே இருக்கின்றது?
[தொகு] எண்ணு கட்டுப்பாட்டு மடக்கி - Count Controlled Loops
FOR I = 1 TO N for I := 1 to N do begin
xxx xxx
NEXT I end;
DO I = 1,N for ( I=1; I<=N; ++I ) {
xxx xxx
END DO }
[தொகு] நிலமை கட்டுப்பாட்டு மடக்கி - Condition Controlled Loops
DO WHILE (test) repeat
xxx xxx
END DO until test;
while (test) { do
xxx xxx
} while (test);
[தொகு] திரட்டு கட்டுப்பாட்டு மடக்கி - Collection Controlled Loops
A few programming languages (e.g. Smalltalk, Perl, Java, C#, Visual Basic) have special constructs which allow you to implicitly loop through all elements of an array, or all members of a set or collection.
someCollection do: [ :eachElement | xxx ].
foreach someArray { xxx }
Collection<String> coll; for (String s : coll) {}
foreach (string s in myStringCollection) { xxx }

