Concepts of Structured Programming Language

Structured programming हर program को सिर्फ 3 shapes से बनाती है, sequence, selection और iteration, blocks में सजाकर जिनका एक रास्ता अंदर और एक बाहर है, इसीलिए C code ऊपर से नीचे पढ़ा जा सकता है।

9 min read · 9 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

2 तरह के class notes

Exam से पहले 2 toppers आपको notes उधार देते हैं।

Notebook एक ऊपर से नीचे पढ़ी जाती है: headings, numbered points, खत्म।

Notebook 2 एक भूलभुलैया है: "page 12 देखो", page 12 कहता है "page 3 से आगे पढ़ो, अगर page 7 से नहीं आए तो"। हर line कहीं और इशारा करती है। 10 minute में आप खो चुके हैं।

शुरुआती programs notebook 2 जैसे थे, और उन्हीं पर planes और payrolls चलते थे। जो सफाई हुई उसका नाम है structured programming, और C उसे लागू करने के लिए ही बनी है।

Theory

Spaghetti बनाम जिल्दबंद किताब

बेतरतीब jumps से भरे code का nickname पड़ा spaghetti code: एक strand खींचो और 20 हिलती हैं, क्योंकि goto statements program को कटोरी के noodles की तरह आर-पार जोड़ते हैं। Structured program जिल्दबंद किताब है: chapters (functions), sections (blocks), हर एक ऊपर से नीचे, एक entry, एक exit। आप chapter 5 खोलकर पूरी कटोरी खोले बिना उसे समझ सकते हैं।

Theory

3 shapes, ठीक-ठीक

Structured programming का दावा, 1966 में mathematically सिद्ध: कोई भी program logic सिर्फ 3 structures से बन सकती है:

  • Sequence: statements एक के बाद एक, क्रम में।
  • Selection: condition से रास्ता चुनना (if, if-else, switch)।
  • Iteration: जब तक condition सही है दोहराना (while, do-while, for)।

सब कुछ blocks { } और functions के अंदर nest होता है, हर एक की single entry और single exit। कोई जंगली कूद नहीं। C आपको ठीक यही tools देती है, इसीलिए वह structured language कहलाती है।

At a glance

तीनों control structures

Structureकिस सवाल का जवाबC के constructs
Sequenceआगे क्या होगा?Statements, एक-एक line
Selectionकौन सा रास्ता लें?if, if-else, switch
Iterationकितनी बार?while, do-while, for

Quiz

इनमें से कौन structured programming के 3 control structures में NAHI है?

  1. बेतरतीब कूद (goto)
  2. Sequence
  3. Selection
  4. Iteration
Show the answer

बेतरतीब कूद (goto)

Structured programming बनी ही इसलिए कि बेतरतीब goto jumps की जगह अनुशासित 3 आएं: sequence, selection, iteration। C में goto keyword अब भी है, दुर्लभ emergencies के लिए (Unit 2 में मिलेगा), पर discipline का पूरा मतलब है कि उसकी ज़रूरत लगभग कभी न पड़े।

Think first

अपने ही program की झलक

Marks program के लिए आगे सोचिए: student का नाम print करना, फिर pass या fail तय करना, फिर class के सभी 60 students को process करना। हर हिस्सा 3 में से कौन सा structure use करेगा?

Show the answer

Lines क्रम से print करना: sequence (आज program के पास बस यही है)। Pass या fail: selection, वही if-else जो आप Unit 2 में लिखेंगे। सभी 60 students: iteration, उसके ठीक बाद वाले loops। पूरे subject का roadmap सच में 3 structures ही हैं, क्रम से पढ़ाए हुए। यह संयोग नहीं; यह syllabus का theory के पीछे चलना है।

Watch out

Marks कहाँ कटते हैं

Structured को object-oriented से मिला देना: C structured है, OOP नहीं; classes और objects आगे के semesters में C++/Java के हैं, और definition में दोनों terms मिलाने पर marks कटते हैं। दूसरा leak: तीनों structures को गोल-मोल कहना ("loops वगैरह")। तिकड़ी को sequence, selection, iteration नाम से याद कीजिए, हर एक के साथ C का एक construct, वही exact wording definition के marks लाती है।

Theory

यह discipline आपकी salary क्यों बनेगी

Structured code कोई सजावट नहीं: इसी वजह से teammate आपका पूरा program पढ़े बिना आपका function ठीक कर पाता है, testers blocks को अलग-थलग test कर पाते हैं, और million-line systems सम्भाले जा पाते हैं। हर code review चुपचाप यही पूछता है: "is this structured?"। अगला lesson उन tools के नाम रखेगा जो ऐसे code को चलाते हैं: editor, compiler, interpreter।

Summary

Key takeaways

  • Structured programming सारी logic 3 structures से बनाती है: sequence, selection, iteration।
  • Code blocks और functions में सजता है, single entry और single exit के साथ।
  • बेतरतीब goto jumps spaghetti code बनाते हैं; discipline उन्हीं से बचने के लिए है।
  • C structured language है; structured का मतलब object-oriented NAHI है।
  • फायदे: ऊपर-से-नीचे readability, अलग-अलग testing, teamwork।
  • Memory hook: sequence, selection, iteration, बस यही 3 shapes चाहिए।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction to C language

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Concepts of Structured Programming Language · Computer Programming and Programming Methodology (CPPM) · Gri-Learn