duplicates - How to avoid while-loop code duplication? -


  स्ट्रिंग s = कंसोल.रिडलाइन (); जबकि (एस! = नल) {// कुछ करना / / .... s = कंसोल.रिडलाइन (); }   

उपरोक्त कोड इनपुट प्राप्त करना, इसे सत्यापित करने, उसे संसाधित करना और फिर इनपुट करना है, लेकिन जाहिर है, s = Console.ReadLine (); कोड दोहराव।

दोहराव से बचने के लिए क्या युक्तियां हैं?

पायथन में (जहां कम से कम एक पुनरावृत्ति की गारंटी देने के लिए कोई do-while लूप नहीं है), यह चाल एक स्पष्ट विराम के साथ अनंत लूप का उपयोग करना है।

  जबकि (सत्य ) // या जो कुछ भी सच बिना शर्त का मूल्यांकन करता है {s = Console.ReadLine (); यदि (एस == रिक्त) {ब्रेक; } // कुछ करो}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -