Perl | last in loop - GeeksforGeeks

文章推薦指數: 80 %
投票人數:10人

last keyword is used to loop control statement which immediately causes the current iteration of the loop to become the last. If a label given, ... Skiptocontent CoursesForWorkingProfessionalsDSAClasses(Live)SystemDesign(Live)JavaBackendDeveloper(Live)FullStack(Live)ExploreMoreLiveCoursesDSA(Self-Paced)SDETheory(Self-Paced)AllDevelopmentCourses(Self-Paced)ExploreMoreSelf-PacedCoursesForStudentsCompetitiveProgramming(Live)GATECourse2023(Live)DataScience(Live)ExploreMoreLiveCoursesDSA(Self-Paced)CIP(Self-Paced)JAVA/Python/C++(Self-Paced)ExploreMoreSelf-PacedCoursesSchoolCoursesSchoolGuidePythonProgrammingLearnToMakeAppsExploremoreAllCoursesTutorialsAlgorithmsAnalysisofAlgorithmsAsymptoticAnalysisWorst,AverageandBestCasesAsymptoticNotationsLittleoandlittleomeganotationsLowerandUpperBoundTheoryAnalysisofLoopsSolvingRecurrencesAmortizedAnalysisWhatdoes'SpaceComplexity'mean?Pseudo-polynomialAlgorithmsPolynomialTimeApproximationSchemeATimeComplexityQuestionSearchingAlgorithmsSortingAlgorithmsGraphAlgorithmsPatternSearchingGeometricAlgorithmsMathematicalBitwiseAlgorithmsRandomizedAlgorithmsGreedyAlgorithmsDynamicProgrammingDivideandConquerBacktrackingBranchandBoundAllAlgorithmsDataStructuresArraysLinkedListStackQueueBinaryTreeBinarySearchTreeHeapHashingGraphAdvancedDataStructureMatrixStringsAllDataStructuresInterviewCornerCompanyPreparationTopTopicsPracticeCompanyQuestionsInterviewExperiencesExperiencedInterviewsInternshipInterviewsCompetititveProgrammingDesignPatternsSystemDesignTutorialMultipleChoiceQuizzesLanguagesCC++JavaPythonC#SQLScalaPerlGoLanguageKotlinWebDevelopmentHTMLCSSJavaScriptPHPCSSFrameworksBootstrapTailwindCSSFoundationCSSMaterializeCSSBulmaPureCSSPrimerCSSBlazeUISemanticUIJavaScriptFrameworksAngularJSNodeJSJavaScriptLibrariesjQueryReactJSML&DataScienceMachineLearningDataScienceCSSubjectsMathematicsOperatingSystemDBMSComputerNetworksComputerOrganizationandArchitectureTheoryofComputationCompilerDesignDigitalLogicSoftwareEngineeringGATEGATEComputerScienceNotesLastMinuteNotesGATECSSolvedPapersGATECSOriginalPapersandOfficialKeysGATE2021DatesGATECS2021SyllabusImportantTopicsforGATECSSoftwareDesignsSoftwareDesignPatternsSystemDesignTutorialGFGSheetsWebDevCheatSheetsHTMLCheatSheetCSSCheatSheetJSCheatSheetjQueryCheatSheetCompany-WiseSDESheetsFacebookSDESheetAmazonSDESheetAppleSDESheetNetflixSDESheetGoogleSDESheetWiproCodingSheetInfosysCodingSheetTCSCodingSheetCognizantCodingSheetHCLCodingSheetDSASheetsSDESheetFAANGCodingSheetLoveBabbarSheetMassRecruiterSheetProduct-BasedCodingSheetCompany-WisePreparationSheetArraySheetStringSheetTreeSheetGraphSheetDPSheetSchoolLearningSchoolProgrammingMathematicsNumberSystemAlgebraTrigonometryStatisticsProbabilityGeometryMensurationCalculusMathsNotes(Class8-12)Class8NotesClass9NotesClass10NotesClass11NotesClass12NotesNCERTSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionRDSharmaSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionPhysicsNotes(Class8-11)Class8NotesClass9NotesClass10NotesClass11NotesChemistryNotesClass8NotesClass9NotesClass10NotesBusinessStudies(Class11th)BusinessStudies(Class12th)CSExams/PSUsISROISROCSOriginalPapersandOfficialKeysISROCSSolvedPapersISROCSSyllabusforScientist/EngineerExamUGCNETUGCNETCSNotesPaperIIUGCNETCSNotesPaperIIIUGCNETCSSolvedPapersStudentCampusAmbassadorProgramSchoolAmbassadorProgramProjectGeekoftheMonthCampusGeekoftheMonthPlacementCourseCompetititveProgrammingTestimonialsStudentChapterGeekontheTopInternshipCareersUPSCGeographyNotesHistoryNotesScience&Tech.NotesEthicsNotesPolityNotesEconomicsNotesUPSCPreviousYearPapersSSCCGLSSCCGLSyllabusGeneralStudiesEnglishReasoningSubjectwisePracticePapersPreviousYearPapersBankingExamsSBIClerkSBIClerkSyllabusGeneralAwarenessEnglishQuantitativeAptitudeReasoningAbilitySBIClerkPracticePapersSBIPOSBIPOSyllabusGeneralAwarenessEnglishQuantitativeAptitudeReasoningAbilityPreviousYearPapersSBIPOPracticePapersIBPSPOIBPSPO2022SyllabusEnglishNotesReasoningNotesPreviousYearPapersMockQuestionPapersIBPSClerkIBPSClerkSyllabusEnglishNotesPreviousYearPapersJobsApplyforJobsPostaJobHirewithUsKnowaboutJobathonJobathonPracticeAllDSAProblemsProblemoftheDayInterviewSeries:WeeklyContestsBi-WizardCoding:SchoolContestsEventsPracticeSDESheetCuratedDSAListsTop50ArrayProblemsTop50StringProblemsTop50TreeProblemsTop50GraphProblemsTop50DPProblemsContests HomeSavedVideosCoursesGBlogPuzzlesWhat'sNew? ChangeLanguage DataStructuresAlgorithmsInterviewPreparationTopic-wisePracticeC++JavaPythonCompetitiveProgrammingMachineLearningWrite&EarnJavaScriptSDESheetPuzzlesGFGSchoolProjects RelatedArticles ▲RelatedArticlesWriteanArticleWriteArticlesPickTopicstowriteGuidelinestoWriteGetTechnicalWritingInternshipWriteanInterviewExperiencePerl|lastinloopPerl|DataTypesPerl|BasicSyntaxofaPerlProgramHelloWorldPrograminPerlPerl|BooleanValuesPerl|Operators|Set–1Perl|Operators|Set–2Perl|VariablesPerl|ModulesPackagesinPerlPerl|Loops(for,foreach,while,do…while,until,Nestedloops)Perl|DecisionMaking(if,if-else,Nested–if,if-elsifladder,unless,unless-else,unless-elsif)Perl|split()FunctionPerl|chomp()FunctionPerl|chop()FunctionPerl|Removingleadingandtrailingwhitespaces(trim)Perl|StringOperatorsPerl|Stringfunctions(length,lc,uc,index,rindex)Perl|UsefulStringfunctionsPerl|UsefulArrayfunctionsPerl|exists()FunctionPerl|grep()FunctionPerl|SearchinginaFileusingregexPerl|RegularExpressionsPerl|OperatorsinRegularExpressionPerl|push()FunctionPerl|substr()functionWriteanArticleWriteArticlesPickTopicstowriteGuidelinestoWriteGetTechnicalWritingInternshipWriteanInterviewExperiencePerl|lastinloopPerl|DataTypesPerl|BasicSyntaxofaPerlProgramHelloWorldPrograminPerlPerl|BooleanValuesPerl|Operators|Set–1Perl|Operators|Set–2Perl|VariablesPerl|ModulesPackagesinPerlPerl|Loops(for,foreach,while,do…while,until,Nestedloops)Perl|DecisionMaking(if,if-else,Nested–if,if-elsifladder,unless,unless-else,unless-elsif)Perl|split()FunctionPerl|chomp()FunctionPerl|chop()FunctionPerl|Removingleadingandtrailingwhitespaces(trim)Perl|StringOperatorsPerl|Stringfunctions(length,lc,uc,index,rindex)Perl|UsefulStringfunctionsPerl|UsefulArrayfunctionsPerl|exists()FunctionPerl|grep()FunctionPerl|SearchinginaFileusingregexPerl|RegularExpressionsPerl|OperatorsinRegularExpressionPerl|push()FunctionPerl|substr()functionPerl|lastinloopViewDiscussion ImproveArticle SaveArticle LikeArticle LastUpdated: 27Feb,2019ReadDiscussViewDiscussion ImproveArticle SaveArticle LikeArticle lastkeywordisusedtoloopcontrolstatementwhichimmediatelycausesthecurrentiterationofthelooptobecomethelast.Ifalabelgiven,thenitcomesoftheloopbythelabel.Syntax:#Comesoutofthecurrentloop.last#Comesoutoftheloopspecifiedby#MY_LABELlastMY_LABELExample1:#!/usr/bin/perl$sum=0;$a=0;$b=0;  while(1) {  $sum=$a+$b;$a=$a+2;  #Conditiontoendtheloopif($sum>10) {    print"Sum=$sum\n";    print"Exitingtheloop\n";    last;} else{    $b=$b-1;}}print"LoopendedatSum>10\n";Output: Sum=11 Exitingtheloop LoopendedatSum>10 Example2:#!/usr/local/bin/perl  $a=1;$sum=0;  #OuterLoopLabel1:while($a<16) {   $b=1;        #InnerLoop   Label2:while($b<8)   {      $sum=$sum+$b;      if($a==8)       {         print"Sumis$sum";                    #terminateouterloop         lastLabel1;      }      $b=$b*2;   }   $a=$a*2;}Output:Sumis22MyPersonalNotes arrow_drop_upSave LikeNext Perl|DataTypesRecommendedArticlesPage:13,Jun1913,Nov1920,Nov1902,Aug1802,May1903,Jul1930,May1929,Apr1926,Apr1928,Feb1913,Jul1820,Jun1820,Jun1820,Jun1825,Jun1818,Jul1826,Jun1828,Jun1803,Jul1803,Jul1803,Jul1806,Jul1812,Jul1818,Jul18ArticleContributedBy:Code_Mech@Code_MechVotefordifficultyEasy Normal Medium Hard ExpertArticleTags:perl-basicsPerl-LoopsPerlPracticeTags:PerlReportIssueWritingcodeincomment? Pleaseuseide.geeksforgeeks.org, generatelinkandsharethelinkhere. LoadCommentsPleaseLogintocomment...What'sNew  ViewDetailsViewDetailsViewDetailsImproveyourCodingSkillswithPracticeTryIt! Weusecookiestoensureyouhavethebestbrowsingexperienceonourwebsite.Byusingoursite,you acknowledgethatyouhavereadandunderstoodour CookiePolicy& PrivacyPolicy GotIt! StartYourCodingJourneyNow!Login Register



請為這篇文章評分?