Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6471025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:10:39+00:00 2026-05-25T06:10:39+00:00

Is it possible to implement something like a Smalltalk-style whileTrue: method in Objective-C using

  • 0

Is it possible to implement something like a Smalltalk-style whileTrue: method in Objective-C using blocks? Specifically, instead of:

int count = 0;
while (count < 10)
{
  NSLog(count);
  count++;
}

I’d like to be able to do (via a wrapper on the bool primitive called OOBoolean) something like…

__block int count = 0;
[[OOBoolean booleanWithBool: count < 10] whileTrueDo: ^() {
  NSLog(count);
  count++;
}];

I’m having trouble understanding how this would be implemented though…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:10:41+00:00Added an answer on May 25, 2026 at 6:10 am

    Here you have a couple of ideas,

    Assuming your bool wrapper implements boolValue, a naive implementation could be:

    -(void) whileTrueDo:(void (^)(void)) block{
        while ([self boolValue]) {
            block();
        }
    }
    

    In order for the wrapper to change its bool value after each iteration, the block must be able to actually change the variable that is used to calculate the boolean condition. So, in your case, by setting the __block type modifier to count, and increasing count in each block execution, you should be able to make it work.

    The problem is, if you create your wrapper by sending the evaluated condition, as you stated in your question, you wont be able to change its bool value in each iteration. So, I would change the way the wrapper is created and the whileTrueDo: naive implementation so the boolean wrapper uses an evaluation block.

       __block int count = 0;
        OOBooleanBlock evaluationBlock =  ^BOOL{
            return count < 10;
        };
        [[OOBoolean booleanWithBlock:evaluationBlock] whileTrueDo: ^() {
            NSLog(count);
            count++;
        }];
    
    //In OOBoolean 
    +(OOBoolean*) booleanWithBlock:(OOBooleanBlock) evaluationBlock{
    //Instantiate, set the evaluationBlock ivar and return the ooboolean object.
    } 
    
    -(void) whileTrueDo:(void (^)(void)) block{
        while (self.evaluationBlock()) {
            block();
        }
    }
    

    Remember to use the __block type modifier, otherwise you will enter in an infinite loop.

    I haven’t tested this, I hope this helps you though.

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to implement in Python something like this simple one: #!/usr/bin/perl my
I have implement something like the following on J2me. Is it possible to implement
I am trying to implement something like google instant seach that displays possible searches
Is it possible to implement something like the following trigger CREATE TRIGGER [tr_AU_ddl_All_Server] ON
It's possible to implement INotifyCollectionChanged or other interface like IObservable to enable to bind
Is it possible to define something like this in java? C# code: public enum
I'm trying to implement something like a photo carousel in jQuery. This carousel could
For an assignment, we had to implement something like a very basic sexp parser,
I'm hoping to implement something like all of the great plugins out there for
im interested to implement something but im not sure if it would be possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.